package com.jservice.framework.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jservice.framework.utils.StringUtils;
import com.jservice.framework.utils.WebUtils;
import com.jservice.framework.freemarker.directive.FlashMessageDirective;

/**
 * FlashMessageInterceptor
 *
 * @Author cwledit
 * @DATE 2017/5/4.
 */
public class FlashMessageInterceptor implements Interceptor {
    @Override
    public void intercept(Invocation inv) {

        String message = WebUtils.getCookie(inv.getController().getRequest(), FlashMessageDirective.FLASH_MESSAGE_ATTRIBUTE_NAME);
        if(StringUtils.isNotEmpty(message)){
            WebUtils.removeCookie(inv.getController().getRequest(),inv.getController().getResponse(),FlashMessageDirective.FLASH_MESSAGE_ATTRIBUTE_NAME);
        }
        inv.invoke();
    }
}
